package com.william.jdbcplus.boot.test.dao.impl;

import com.william.jdbcplus.boot.starter.util.DaoUtil;
import com.william.jdbcplus.boot.test.dao.SysRoleDao;
import com.william.jdbcplus.boot.test.entity.SysRoleMenu;
import com.william.jdbcplus.boot.test.entity.SysUserRole;
import com.william.jdbcplus.core.query.EntityWrap;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@AllArgsConstructor
public class SysRoleDaoImpl implements SysRoleDao {
    /**
     * @param roleId
     * @Author scott
     * @Date 2019/12/13 16:12
     * @Description: 删除角色与用户关系
     */
    @Override
    public void deleteRoleUserRelation(String roleId) {
        // @Delete("delete from sys_user_role where role_id = #{roleId}")
        EntityWrap<SysUserRole> wrapper = new EntityWrap<>(SysUserRole.class);
        wrapper.lambda().eq(SysUserRole::getRoleId, roleId);
        DaoUtil.BASE.delete(wrapper);
    }

    /**
     * @param roleId
     * @Description: 删除角色与权限关系
     */
    @Override
    public void deleteRolePermissionRelation(String roleId) {
        // @Delete("delete from sys_role_permission where role_id = #{roleId}")
        EntityWrap<SysRoleMenu> wrapper = new EntityWrap<>(SysRoleMenu.class);
        wrapper.lambda().eq(SysRoleMenu::getRoleId, roleId);
        DaoUtil.BASE.delete(wrapper);
    }
}
